/*
 * Board    INT.  0   1   2   3   4   5
 * Mega2560 PIN   2   3  21  20  19  18
 * 
 * 
 * 
 * 
 *  attachInterrupt(digitalPinToInterrupt(pin), ISR, mode) 
 * interrupt: the number of the interrupt. Allowed data types: int.
 * pin: the Arduino pin number.
 * mode: defines when the interrupt should be triggered. 
 *      Four constants are predefined as valid values:
 *  LOW to trigger the interrupt whenever the pin is low,
 *  CHANGE to trigger the interrupt whenever the pin changes value
 *  RISING to trigger when the pin goes from low to high,
 *  FALLING for when the pin goes from high to low.
 *  HIGH to trigger the interrupt whenever the pin is high.
 */

#define unsigned long ulong

const byte ledPin = 13;

const byte interruptPin = 21;

volatile byte state = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), click, RISING  );
  Serial.begin(9600);
  Serial.println("Init Finished!");
}

void loop() {
    digitalWrite(ledPin, state);
}

void click() {
  state = !state;
}
